package com.xiaoxu.intranetweb.mybatisplusSzappdb.controller.auth;


import com.alibaba.fastjson.JSONObject;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.business.auth.PersonnelBu;
import com.xiaoxu.intranetweb.util.SzResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@CrossOrigin()
@RestController
@RequestMapping(value = "/personnel")
public class PersonnelController {
@Autowired
private PersonnelBu personnelBu;
    //查询现场用户
    @GetMapping("/getPersonnel")
    public SzResult getPersonnel(@RequestParam(required = false) String name, @RequestParam String page,@RequestParam String pageSize, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return personnelBu.getPersonnel(name, plantId,page,pageSize);
    }

    //新增现场用户
    @PostMapping("/addPersonnel")
    public SzResult addPersonnel(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        String name = jsonObject.getString("name");
        String pwd = jsonObject.getString("pwd");
        return personnelBu.addPersonnel(name,pwd, plantId);
    }

    //修改现场用户
    @PostMapping("/updatePersonnel")
    public SzResult updatePersonnel(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        String id = jsonObject.getString("id");
        String name = jsonObject.getString("name");
        String pwd = jsonObject.getString("pwd");
        return personnelBu.updatePersonnel(name,pwd, plantId,id);
    }
    //删除现场用户
    @PostMapping("/deletePersonnel")
    public SzResult deletePersonnel(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        String id = jsonObject.getString("id");
        return personnelBu.deletePersonnel(id, plantId);
    }
}
